package com.glsc.ngateway.common.base.enums.itflow;

import com.glsc.ngateway.common.base.exception.PlatformException;
import lombok.AllArgsConstructor;
import lombok.Getter;

import javax.validation.constraints.NotBlank;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

/**
 * 各流程中的各个节点命名
 *
 * @author xuchang
 */
@Getter
@AllArgsConstructor
public enum ITFlowTaskEnum {
    /**
     * 设备变更流程
     */
    //1流程发起
    MODIFY_FLOW_BEGIN_TASK("equipmentModifyFlowBeginTask", "beginTask", "1流程发起", null,
            ITFlowTaskParamEnum.MODIFY_FLOW_BEGIN_TASK_ASSIGNMENTS, Collections.emptyList()),
    //2部门负责人审批
    MODIFY_FLOW_DEPARTMENT_SUPER_TASK("equipmentModifyFlowDepartmentSuperTask", "departmentSuperTask", "2部门负责人审批", null,
            ITFlowTaskParamEnum.MODIFY_FLOW_DEPARTMENT_SUPER_TASK_ASSIGNMENTS, Collections.emptyList()),
    //3设备管理员库存确认
    MODIFY_FLOW_DEVICE_ADMIN_TASK("equipmentModifyFlowDeviceAdminTask", "deviceAdminTask", "3设备管理员库存确认", null,
            ITFlowTaskParamEnum.MODIFY_FLOW_DEVICE_ADMIN_TASK_ASSIGNMENTS, List.of(ITFlowTaskRoleEnum.ROLE_DEVICE_ADMIN)),
    //4信息技术总部基础架构负责人
    MODIFY_FLOW_FRAMEWORK_HEAD_TASK("equipmentModifyFlowFrameworkHeadTask", "frameworkHeadTask", "4信息技术总部基础架构负责人", null,
            ITFlowTaskParamEnum.MODIFY_FLOW_FRAMEWORK_HEAD_TASK_ASSIGNMENTS, Collections.emptyList()),
    //5_1信息技术总部设备管理员审核
    MODIFY_FLOW_HEAD_QUARTERS_ADMIN_TASK("equipmentModifyFlowHeadQuartersAdminTask", "headQuartersAdminTask", "5_1信息技术总部设备管理员审核", null,
            ITFlowTaskParamEnum.MODIFY_FLOW_HEAD_QUARTERS_ADMIN_TASK_ASSIGNMENTS, List.of(ITFlowTaskRoleEnum.ROLE_DEVICE_ADMIN)),
    //5_2病毒管理员审批
    MODIFY_FLOW_VIRUS_MANAGE_TASK("equipmentModifyFlowVirusManageTask", "virusManageTask", "5_2病毒管理员审批", null,
            ITFlowTaskParamEnum.MODIFY_VIRUS_MANAGE_TASK_ASSIGNMENTS, List.of(ITFlowTaskRoleEnum.ROLE_VIRUS_MANAGER)),
    /**
     * 设备申领流程
     */
    //1流程发起
    APPLY_FLOW_BEGIN_TASK("equipmentApplyFlowBeginTask", "beginTask", "1流程发起", null,
            ITFlowTaskParamEnum.APPLY_FLOW_BEGIN_TASK_ASSIGNMENTS, Collections.emptyList()),
    //2部门负责人审批
    APPLY_FLOW_DEPARTMENT_SUPER_TASK("equipmentApplyFlowDepartmentSuperTask", "departmentSuperTask", "2部门负责人审批", null,
            ITFlowTaskParamEnum.APPLY_FLOW_DEPARTMENT_SUPER_TASK_ASSIGNMENTS, Collections.emptyList()),
    //3设备管理员库存确认
    APPLY_FLOW_DEVICE_ADMIN_TASK("equipmentApplyFlowDeviceAdminTask", "deviceAdminTask", "3设备管理员库存确认", null,
            ITFlowTaskParamEnum.APPLY_FLOW_DEVICE_ADMIN_TASK_ASSIGNMENTS, List.of(ITFlowTaskRoleEnum.EQUIPMENT_ADMIN)),
    //4网络安全部门责任人审核
    APPLY_FLOW_NET_WORK_SECURITY_TASK("equipmentApplyFlowNetworkSecurityTask", "networkSecurityTask", "4网络安全部门责任人审核", null,
            ITFlowTaskParamEnum.APPLY_FLOW_NETWORK_SECURITY_TASK_ASSIGNMENTS, List.of(ITFlowTaskRoleEnum.ROLE_NET_ADMIN)),
    //5_1设备管理员分配资源
    APPLY_FLOW_DEVICE_ADMIN_ASSIGNMENT_TASK("equipmentApplyFlowDeviceAdminAssignmentTask", "deviceAdminAssignmentTask", "5_1设备管理员分配资源", null,
            ITFlowTaskParamEnum.APPLY_FLOW_DEVICE_ADMIN_ASSIGNMENT_TASK_ASSIGNMENTS, List.of(ITFlowTaskRoleEnum.EQUIPMENT_ADMIN)),
    //5_2病毒管理员审批
    APPLY_FLOW_VIRUS_MANAGE_TASK("equipmentApplyFlowVirusManageTask", "virusManageTask", "5_2病毒管理员审批", null,
            ITFlowTaskParamEnum.APPLY_VIRUS_MANAGE_TASK_ASSIGNMENTS, List.of(ITFlowTaskRoleEnum.ROLE_VIRUS_MANAGER)),
    /**
     * 设备下架流程
     */
    //1流程发起
    OFFLINE_FLOW_BEGIN_TASK("equipmentOfflineFlowBeginTask", "beginTask", "1流程发起", null,
            ITFlowTaskParamEnum.OFFLINE_FLOW_BEGIN_TASK_ASSIGNMENTS, Collections.emptyList()),
    //2部门负责人审批
    OFFLINE_FLOW_DEPARTMENT_SUPER_TASK("equipmentOfflineFlowDepartmentSuperTask", "departmentSuperTask", "2部门负责人审批", null,
            ITFlowTaskParamEnum.OFFLINE_FLOW_DEPARTMENT_SUPER_TASK_ASSIGNMENTS, Collections.emptyList()),
    //3机房管理员处理
    OFFLINE_FLOW_ROOM_ADMIN_TASK("equipmentOfflineFlowRoomAdminTask", "roomAdminTask", "3机房管理员处理", null,
            ITFlowTaskParamEnum.OFFLINE_FLOW_ROOM_ADMIN_TASK_ASSIGNMENTS, List.of(ITFlowTaskRoleEnum.ROLE_ROOM_ADMIN)),
    //4设备管理员库存确认
    OFFLINE_FLOW_DEVICE_ADMIN_TASK("equipmentOfflineFlowDeviceAdminTask", "deviceAdminTask", "4设备管理员库存确认", null,
            ITFlowTaskParamEnum.OFFLINE_FLOW_DEVICE_ADMIN_TASK_ASSIGNMENTS, List.of(ITFlowTaskRoleEnum.ROLE_DEVICE_ADMIN)),
    //5_1网络管理员审核
    OFFLINE_FLOW_NET_ADMIN_TASK("equipmentOfflineFlowNetAdminTask", "netAdminTask", "5_1网络管理员审核", null,
            ITFlowTaskParamEnum.OFFLINE_FLOW_NET_ADMIN_TASK_ASSIGNMENTS, List.of(ITFlowTaskRoleEnum.ROLE_NET_ADMIN)),
    //5_2病毒管理员审批
    OFFLINE_FLOW_VIRUS_MANAGE_TASK("equipmentOfflineFlowVirusManageTask", "virusManageTask", "5_2病毒管理员审批", null,
            ITFlowTaskParamEnum.OFFLINE_VIRUS_MANAGE_TASK_ASSIGNMENTS, List.of(ITFlowTaskRoleEnum.ROLE_VIRUS_MANAGER)),
    /**
     * 物理设备申领及上架流程
     */
    //1流程发起
    SERVER_APPLY_FLOW_BEGIN_TASK("equipmentServerApplyFlowBeginTask", "beginTask", "1流程发起", null,
            ITFlowTaskParamEnum.SERVER_APPLY_FLOW_BEGIN_TASK_ASSIGNMENTS, Collections.emptyList()),
    //2部门负责人审批
    SERVER_APPLY_FLOW_DEPARTMENT_SUPER_TASK("equipmentServerApplyFlowDepartmentSuperTask", "departmentSuperTask", "2部门负责人审批", null,
            ITFlowTaskParamEnum.SERVER_APPLY_FLOW_DEPARTMENT_SUPER_TASK_ASSIGNMENTS, Collections.emptyList()),
    //3机房管理员审核
    SERVER_APPLY_FLOW_ROOM_ADMIN_TASK("equipmentServerApplyFlowRoomAdminTask", "roomAdminTask", "3机房管理员审核", null,
            ITFlowTaskParamEnum.SERVER_APPLY_FLOW_ROOM_ADMIN_TASK_ASSIGNMENTS, List.of(ITFlowTaskRoleEnum.ROLE_ROOM_ADMIN)),
    //4网络管理员审核
    SERVER_APPLY_FLOW_NET_ADMIN_TASK("equipmentServerApplyFlowNetAdminTask", "netAdminTask", "4网络管理员审核", null,
            ITFlowTaskParamEnum.SERVER_APPLY_FLOW_NET_ADMIN_TASK_ASSIGNMENTS, List.of(ITFlowTaskRoleEnum.ROLE_NET_ADMIN)),
    //5基础架构部负责人审核
    SERVER_APPLY_FLOW_HEAD_OF_INFRASTRUCTURE_DEPARTMENT_TASK("equipmentServerApplyFlowHeadOfInfrastructureDepartmentTask", "headOfInfrastructureDepartmentTask", "5基础架构部负责人审核", null,
            ITFlowTaskParamEnum.SERVER_APPLY_FLOW_HEAD_OF_INFRASTRUCTURE_DEPARTMENT_TASK_ASSIGNMENTS, List.of(ITFlowTaskRoleEnum.ROLE_FRAMEWORK_HEAD)),
    //6设备管理员库存确认
    SERVER_APPLY_FLOW_DEVICE_ADMIN_TASK("equipmentServerApplyFlowDeviceAdminTask", "deviceAdminTask", "6设备管理员库存确认", null,
            ITFlowTaskParamEnum.SERVER_APPLY_FLOW_DEVICE_ADMIN_TASK_ASSIGNMENTS, List.of(ITFlowTaskRoleEnum.ROLE_DEVICE_ADMIN)),
    //7_1设备管理员复核
    SERVER_APPLY_FLOW_DEVICE_ADMIN_REVIEW_TASK("equipmentServerApplyFlowDeviceAdminReviewTask", "deviceAdminReviewTask", "7_1设备管理员复核", null,
            ITFlowTaskParamEnum.SERVER_APPLY_FLOW_DEVICE_ADMIN_REVIEW_TASK_ASSIGNMENTS, List.of(ITFlowTaskRoleEnum.ROLE_DEVICE_ADMIN)),
    //7_2病毒管理员审批
    SERVER_APPLY_FLOW_VIRUS_MANAGE_TASK("equipmentServerApplyFlowVirusManageTask", "virusManageTask", "7_2病毒管理员审批", null,
            ITFlowTaskParamEnum.SERVER_APPLY_VIRUS_MANAGE_TASK_ASSIGNMENTS, List.of(ITFlowTaskRoleEnum.ROLE_VIRUS_MANAGER)),
    //8网络管理员审核
    SERVER_APPLY_FLOW_NET_ADMIN_REVIEW_TASK("equipmentServerApplyFlowNetAdminReviewTask", "netAdminReviewTask", "8网络管理员审核", null,
            ITFlowTaskParamEnum.SERVER_APPLY_FLOW_NET_ADMIN_REVIEW_TASK_ASSIGNMENTS, List.of(ITFlowTaskRoleEnum.ROLE_NET_ADMIN)),
    /**
     * 系统名称申请流程
     */
    //1流程发起
    SYSTEM_NAME_APPLY_FLOW_BEGIN_TASK("systemNameApplyFlowBeginTask", "beginTask", "1流程发起", null,
            ITFlowTaskParamEnum.SYSTEM_NAME_APPLY_FLOW_BEGIN_TASK_ASSIGNMENTS, Collections.emptyList()),
    //2上级领导审批
    SYSTEM_NAME_APPLY_FLOW_LEADER_TASK("systemNameApplyFlowLeaderTask", "leaderTask", "2上级领导审批", SYSTEM_NAME_APPLY_FLOW_BEGIN_TASK,
            ITFlowTaskParamEnum.SYSTEM_NAME_APPLY_FLOW_LEADER_TASK_ASSIGNMENTS, Collections.emptyList()),
    //3一级部门负责人审批
    SYSTEM_NAME_APPLY_FLOW_DEPARTMENT_SUPER_TASK("systemNameApplyFlowDepartmentSuperTask", "departmentSuperTask", "3一级部门负责人审批", SYSTEM_NAME_APPLY_FLOW_LEADER_TASK,
            ITFlowTaskParamEnum.SYSTEM_NAME_APPLY_FLOW_DEPARTMENT_SUPER_TASK_ASSIGNMENTS, Collections.emptyList()),

    /**
     * 系统名称变更流程
     */
    //1流程发起
    SYSTEM_NAME_MODIFY_FLOW_BEGIN_TASK("systemNameModifyFlowBeginTask", "beginTask", "1流程发起", null,
            ITFlowTaskParamEnum.SYSTEM_NAME_MODIFY_FLOW_BEGIN_TASK_ASSIGNMENTS, Collections.emptyList()),
    //2上级领导审批
    SYSTEM_NAME_MODIFY_FLOW_LEADER_TASK("systemNameModifyFlowLeaderTask", "leaderTask", "2上级领导审批", SYSTEM_NAME_MODIFY_FLOW_BEGIN_TASK,
            ITFlowTaskParamEnum.SYSTEM_NAME_MODIFY_FLOW_LEADER_TASK_ASSIGNMENTS, Collections.emptyList()),
    //3一级部门负责人审批
    SYSTEM_NAME_MODIFY_FLOW_DEPARTMENT_SUPER_TASK("systemNameModifyFlowDepartmentSuperTask", "departmentSuperTask", "3一级部门负责人审批", SYSTEM_NAME_MODIFY_FLOW_LEADER_TASK,
            ITFlowTaskParamEnum.SYSTEM_NAME_MODIFY_FLOW_DEPARTMENT_SUPER_TASK_ASSIGNMENTS, Collections.emptyList()),
    /**
     * CMDB配件规格新增/删除流程
     */
    CMDB_PART_STANDARD_MODIFY_FLOW_BEGIN_TASK("cmdbPartStandardModifyFlowBeginTask", "beginTask", "1流程发起",
            null, ITFlowTaskParamEnum.CMDB_PART_STANDARD_MODIFY_FLOW_BEGIN_TASK_ASSIGNMENTS, Collections.emptyList()),
    CMDB_PART_STANDARD_MODIFY_FLOW_CREATOR_AUDIT_TASK("cmdbPartStandardModifyFlowCreatorAuditTask", "beginConfirmTask", "2发起人确认",
            null, ITFlowTaskParamEnum.CMDB_PART_STANDARD_MODIFY_FLOW_CREATOR_AUDIT_TASK_ASSIGNMENTS, Collections.emptyList()),

    /**
     * CMDB服务器规格新增/删除流程
     */
    CMDB_DEVICE_STANDARD_MODIFY_FLOW_BEGIN_TASK("cmdbDeviceStandardModifyFlowBeginTask", "beginTask", "1流程发起",
            null, ITFlowTaskParamEnum.CMDB_DEVICE_STANDARD_MODIFY_FLOW_BEGIN_TASK_ASSIGNMENTS, Collections.emptyList()),
    CMDB_DEVICE_STANDARD_MODIFY_FLOW_CREATOR_AUDIT_TASK("cmdbDEeviceStandardModifyFlowCreatorAuditTask", "beginConfirmTask", "2发起人确认",
            null, ITFlowTaskParamEnum.CMDB_DEVICE_STANDARD_MODIFY_FLOW_CREATOR_AUDIT_TASK_ASSIGNMENTS, Collections.emptyList()),
    /**
     * CMDB配件入库流程
     */
    CMDB_PART_IN_FLOW_BEGIN_TASK("cmdbPartInFlowBeginTask", "beginTask", "1流程发起",
            null, ITFlowTaskParamEnum.CMDB_PART_IN_FLOW_BEGIN_TASK_ASSIGNMENTS, Collections.emptyList()),
    CMDB_PART_IN_FLOW_LEADER_TASK("cmdbPartInFlowLeaderTask", "leaderTask", "2上级领导审批",
            null, ITFlowTaskParamEnum.CMDB_PART_IN_FLOW_LEADER_TASK_ASSIGNMENTS, Collections.emptyList()),
    CMDB_PART_IN_FLOW_CREATOR_AUDIT_TASK("cmdbPartInFlowCreatorAuditTask", "beginConfirmTask", "3发起人确认",
            null, ITFlowTaskParamEnum.CMDB_PART_IN_FLOW_CREATOR_AUDIT_TASK_ASSIGNMENTS, Collections.emptyList()),
    CMDB_PART_IN_FLOW_SYNC_OA_TASK("cmdbPartInFlowSyncOaTask", "syncOaTask", "4同步OA",
            null, ITFlowTaskParamEnum.CMDB_PART_IN_FLOW_SYNC_OA_TASK_ASSIGNMENTS, Collections.emptyList()),
    /**
     * CMDB配件出库流程
     */
    CMDB_PART_OUT_FLOW_BEGIN_TASK("cmdbPartOutFlowBeginTask", "beginTask", "1流程发起",
            null, ITFlowTaskParamEnum.CMDB_PART_OUT_FLOW_BEGIN_TASK_ASSIGNMENTS, Collections.emptyList()),
    CMDB_PART_OUT_FLOW_LEADER_TASK("cmdbPartOutFlowLeaderTask", "leaderTask", "2上级领导审批",
            null, ITFlowTaskParamEnum.CMDB_PART_OUT_FLOW_LEADER_TASK_ASSIGNMENTS, Collections.emptyList()),
    CMDB_PART_OUT_FLOW_CREATOR_AUDIT_TASK("cmdbPartOutFlowCreatorAuditTask", "beginConfirmTask", "3发起人确认",
            null, ITFlowTaskParamEnum.CMDB_PART_OUT_FLOW_CREATOR_AUDIT_TASK_ASSIGNMENTS, Collections.emptyList()),

    /**
     * CMDB设备入库流程
     */
    CMDB_DEVICE_IN_FLOW_BEGIN_TASK("cmdbDeviceInFlowBeginTask", "beginTask", "1流程发起",
            null, ITFlowTaskParamEnum.CMDB_DEVICE_IN_FLOW_BEGIN_TASK_ASSIGNMENTS, Collections.emptyList()),
    CMDB_DEVICE_IN_FLOW_LEADER_TASK("cmdbDeviceInFlowLeaderTask", "leaderTask", "2上级领导审批",
            null, ITFlowTaskParamEnum.CMDB_DEVICE_IN_FLOW_LEADER_TASK_ASSIGNMENTS, Collections.emptyList()),
    CMDB_DEVICE_IN_FLOW_CREATOR_AUDIT_TASK("cmdbDeviceInFlowCreatorAuditTask", "beginConfirmTask", "3发起人确认",
            null, ITFlowTaskParamEnum.CMDB_DEVICE_IN_FLOW_CREATOR_AUDIT_TASK_ASSIGNMENTS, Collections.emptyList()),
    CMDB_DEVICE_IN_FLOW_SYNC_OA_TASK("cmdbDeviceInFlowSyncOaTask", "syncOaTask", "4同步OA",
            null, ITFlowTaskParamEnum.CMDB_DEVICE_IN_FLOW_SYNC_OA_TASK_ASSIGNMENTS, Collections.emptyList()),
    /**
     * CMDB设备入库流程
     */
    CMDB_DEVICE_OUT_FLOW_BEGIN_TASK("cmdbDeviceOutFlowBeginTask", "beginTask", "1流程发起",
            null, ITFlowTaskParamEnum.CMDB_DEVICE_OUT_FLOW_BEGIN_TASK_ASSIGNMENTS, Collections.emptyList()),
    CMDB_DEVICE_OUT_FLOW_LEADER_TASK("cmdbDeviceOutFlowLeaderTask", "leaderTask", "2上级领导审批",
            null, ITFlowTaskParamEnum.CMDB_DEVICE_OUT_FLOW_LEADER_TASK_ASSIGNMENTS, Collections.emptyList()),
    CMDB_DEVICE_OUT_FLOW_CREATOR_AUDIT_TASK("cmdbDeviceOutFlowCreatorAuditTask", "beginConfirmTask", "3发起人确认",
            null, ITFlowTaskParamEnum.CMDB_DEVICE_OUT_FLOW_CREATOR_AUDIT_TASK_ASSIGNMENTS, Collections.emptyList()),


    /**
     * 供应商评价流程
     */
    VENDOR_RATE_BEGIN_TASK("vendorRateBeginTask", "beginTask", "1流程发起",
            null, ITFlowTaskParamEnum.VENDOR_RATE_BEGIN_TASK_ASSIGNMENTS, Collections.emptyList()),
    VENDOR_RATE_SCORE_TASK("vendorRateScoreTask", "rateScoreTask", "2评估人评分",
            null, ITFlowTaskParamEnum.VENDOR_RATE_SCORE_TASK_ASSIGNMENTS, Collections.emptyList()),
    VENDOR_RATE_LEADER_TASK("cmdbDeviceOutFlowCreatorAuditTask", "rateLeaderTask", "3评估人上级确认",
            null, ITFlowTaskParamEnum.VENDOR_RATE_LEADER_TASK_ASSIGNMENTS, Collections.emptyList());

    /**
     * 代码key, 用于标识flow策略下的每一个节点
     */
    private final String mqCodeKey;

    /**
     * flowable-task definenationKey
     */
    private final String taskKey;

    private final String desc;
    /**
     * 上一节点， 用于根据当前节点回退默认上一节点，只有“系统名称申请”和“系统名称变更”使用
     * TODO：变成list，flowable回退至指定节点，可以传list用于回退至网关侧
     */
    private final ITFlowTaskEnum prevTask;

    private final ITFlowTaskParamEnum param;

    private final List<ITFlowTaskRoleEnum> roles;

    public static ITFlowTaskEnum seek(@NotBlank String code) {
        return Arrays.stream(values()).filter(e -> e.getTaskKey().equals(code)).findFirst().orElseThrow(() -> PlatformException.error("未匹配到节点信息：" + code));
    }
}
